<?php

namespace App\Admin\Actions;

use Dcat\Admin\Actions\Action;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Form\Field\Table;
use Dcat\Admin\Grid\Actions\Show;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class FindLineUser extends RowAction
{
    protected $model;

    public function __construct(string $model = null)
    {
        $this->model = $model;
    }

    /**
     * 按钮标题
     *
     * @var string
     */
    protected $title = '查找邀请人';


    public function render(): Modal
    {
        \Dcat\Admin\Widgets\Table::make();
        parent::render();
        $id = $this->row->id;
        $res = get_line_user($id);
        $res = array_reverse($res);
        $all_res = count($res);
        // 这里直接创建一个modal框 model的内容由工具表单提供，这里也需要创建一个工具表单才行->body(\App\Admin\Forms\FindLineUser::make()->payload(['id'=>$this->row->id]))
        return Modal::make()
            ->lg()
            ->title('邀请人关系')
            ->scrollable()
            ->body(view('admin.users.find_line_user', ['id'=>$id,'user_line'=>$res,'all_res'=>$all_res]))
            ->button("查找邀请人")->onShow(
                <<<JS
                console.log('查找邀请人显示弹窗', target, $(this));
                target.find('.box-footer').remove();
                JS
            );
    }


    /**
     * 设置要POST到接口的数据
     *
     * @return array
     */
    public function parameters()
    {
        return [
            // 发送当前行 username 字段数据到接口
            'id' => $this->row->id,
        ];
    }
}
